﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationRemoveShprossSpacerConnector : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Удалить соединитель в рамку"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.Other; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return null; }
        }

        public void Execute(ModelControl modelControl)
        {
            foreach(IComponent selectedComponent in modelControl.ModelContainer.SelectedComponentsStack)
                if (selectedComponent is Shpross)
                {
                    Shpross shpross = selectedComponent as Shpross;
                    if (shpross.SelectedPoint == ShprossPoints.Start && shpross.StartSpacerConnector != null)
                    {
                        shpross.RemoveInnerComponent(shpross.StartSpacerConnector);
                        shpross.StartSpacerConnector = null;
                    }
                    else if (shpross.SelectedPoint == ShprossPoints.End && shpross.EndSpacerConnector != null)
                    {
                        shpross.RemoveInnerComponent(shpross.EndSpacerConnector);
                        shpross.EndSpacerConnector = null;
                    }
                }
        }

        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
